class EventEmitter {
    constructor() {
        this.#listeners = {}
    }

    on(evtName, cb) {
        if (typeof this.#listeners[evtName] === 'undefined') {
            this.#listeners[evtName] = []
        }
        this.#listeners[evtName].push(cb)
    }

    emit(evtName, arg) {
        for (let i = 0; i < this.#listeners[evtName].length; i++) {
            this.#listeners[evtName][i](arg)
        }
    }

    #listeners = null
}

module.exports = {EventEmitter}